// shopping/pages/submit_order/submit_order.js
let get = require('../../../utils/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:getApp().globalData.domain,
    info:null,
    addr:null,
    isAddrWriten:false,
    comment:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      info:wx.getStorageSync('buy_info')
    })

    get("shop/commodity/order",{
      token:wx.getStorageSync('token')
    }).then(res=>{
      let addr = res.data.data
      if(addr[1]!=""||addr[2]!=""){

        this.setData({
          isAddrWriten:true,
          addr
        })
      }
    })

  },
  submit(){
    this.data.info.forEach(x=>{
      get("order/complete",{
        token:wx.getStorageSync("token"),
        name:x.name,
        bid:x.bid,
        number:x.number,
        total:x.bid*x.number,
        weight:x.weight,
        dispatching_method:"普通快递",
        require:x.comment,
        address:x.addr[2],
        img:x.info.img
      },"POST").then(res=>{

      })
    })
    wx.redirectTo({
      url: '/shopping/pages/purchase_success/purchase_success',
    })
    
  }

})